package prickworlds;

import static org.lwjgl.opengl.GL11.*;

import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;

import prickworlds.graphics.FullTexture;
import prickworlds.gui.ActionEvent;
import prickworlds.gui.ActionListener;
import prickworlds.gui.Button;
import prickworlds.gui.Frame;
import prickworlds.structure.KeyEvent;
import prickworlds.structure.ProgramState;

/**
 * the menu that is displayed when the program starts
 * 
 * @author Faruk Acibal, Richard Dziambor, Christian Holzreuter, Nicolas Winkler
 * 
 */
public class MainMenu extends Frame implements ProgramState, ActionListener {
	Button start;
	Button quit;

	FullTexture winforLogo;
	FullTexture darkArrowStudiosLogo;

	public MainMenu() {
		start = new Button("Play", Display.getWidth() / 2 - 200, 200, 400, 50);
		start.addActionListener(this);
		this.add(start);

		quit = new Button("Beenden", Display.getWidth() / 2 - 200, 270, 400, 50);
		quit.addActionListener(this);
		this.add(quit);

		winforLogo = FullTexture.loadImage(Prickworlds.class
				.getResourceAsStream("data/WinforGameCollection256.png"));
		darkArrowStudiosLogo = FullTexture.loadImage(Prickworlds.class
				.getResourceAsStream("data/DAStudiosLogo.png"));
	}

	@Override
	public void actionPerformed(ActionEvent ae) {
		if (ae.getSource() == quit) {
			Prickworlds.requestClose();
		} else if (ae.getSource() == start) {
			Prickworlds.setProgramState(Prickworlds.getGame());
		}
	}

	@Override
	public void display() {
		glClearColor(0.0f, 0.0f, 0.2f, 0f);
		glClear(GL_COLOR_BUFFER_BIT);

		winforLogo.display(Display.getWidth() / 2 - 400, 350, 400, 400);
		darkArrowStudiosLogo.display(Display.getWidth() / 2, 350, 400, 400);

		super.display();
	}

	@Override
	public void handleKeyEvent(KeyEvent event) {
		if (event.type == KeyEvent.Type.PRESSED
				&& event.key == Keyboard.KEY_ESCAPE) {

			Prickworlds.requestClose();
			event.invalidate();
		} else {
			super.handleKeyEvent(event);
		}
	}
}
